package com.hanyi.mvc.handler;


import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// 自定义异常处理器  统一异常处理
//@Component
public class MyExceptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Object o, Exception e) {

        // 记录异常信息,
        System.out.println("异常栈"+e.getStackTrace()[0]);
        System.out.println("异常消息"+e.getMessage());
        System.out.println("异常类型"+e.getClass());
        System.out.println("异常原因"+e.getCause());
        // 添加包扫描
        // 在spring-mvc中添加
        // 返回友好页面提示
        ModelAndView mv = new ModelAndView();
        mv.setViewName("forward:/err.html");
        return mv;
    }
}
